package com.foo.ui_demo_widge;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.TextView;

public class TextViewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_textview);

        TextView tvDemo = findViewById(R.id.tv_demo);
        tvDemo.setText("测试");
        //设置元素的大小
        tvDemo.setWidth(256);
        tvDemo.setHeight(256);
        //设置背景颜色
        tvDemo.setBackgroundColor(Color.GREEN);
        //设置文本颜色
        tvDemo.setTextColor(Color.BLUE);
        //设置文本字体大小i
        tvDemo.setTextSize(TypedValue.COMPLEX_UNIT_PX, 20);
        //设置字体风格
        tvDemo.setTypeface(Typeface.DEFAULT_BOLD);
        //在X缩放
        tvDemo.setScaleX(1.5f);
        //在y缩放
        tvDemo.setScaleY(1.5f);
        //设置背景资源
        tvDemo.setBackgroundResource(R.drawable.ic_launcher_background);
        //设置对齐方式
        tvDemo.setGravity(Gravity.CENTER);
        //设置内边距
        tvDemo.setPadding(10, 30, 10, 0);

    }
}